package hadoop.topN.question1;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class CourseBean implements Writable {
    private String courseName;
    private int stuNum;
    private double courseAvg;

    public CourseBean() {
    }

    public CourseBean(String courseName, int stuNum, int courseAvg) {
        this.courseName = courseName;
        this.stuNum = stuNum;
        this.courseAvg = courseAvg;
    }

    public String getCourseName() {
        return courseName;
    }

    public void setCourseName(String courseName) {
        this.courseName = courseName;
    }

    public int getStuNum() {
        return stuNum;
    }

    public void setStuNum(int stuNum) {
        this.stuNum = stuNum;
    }

    public double getCourseAvg() {
        return courseAvg;
    }

    public void setCourseAvg(double courseAvg) {
        this.courseAvg = courseAvg;
    }

    @Override
    public String toString() {
        return courseName +"\t"+ stuNum +"\t"+ String.format("%.1f",courseAvg);
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeUTF(this.courseName);
        dataOutput.writeInt(this.stuNum);
        dataOutput.writeDouble(this.courseAvg);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.courseName=dataInput.readUTF();
        this.stuNum=dataInput.readInt();
        this.courseAvg=dataInput.readDouble();
    }
}
